package com.rxyb.upms.gate.controller;


import com.rxyb.core.respone.R;
import com.rxyb.security.annotation.Inner;
import com.rxyb.upms.gate.pojo.UserDetailReq;
import com.rxyb.upms.gate.pojo.UserDetailRsp;
import com.rxyb.upms.service.SysRoleService;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YJH
 * @since 2020-05-26
 */
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {


    private final SysRoleService sysRoleService;

    public SysRoleController(SysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }


    /**
     * 获取用户信息
     *
     * @param req
     * @return
     */
    @Inner
    @PostMapping(value = "userDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<UserDetailRsp> userDetail(@RequestBody UserDetailReq req) {
        return sysRoleService.findUserDetail(req);
    }


    @PreAuthorize("hasAuthority('ROLE_1')")
    @GetMapping("test")
    public Object test(Authentication authentication) {
        return authentication.getAuthorities();
    }
}
